﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class SmartTriggerActionsController : ControllerBase
    {

        private readonly ISmartTriggerActionAppService _app;
        public SmartTriggerActionsController(ISmartTriggerActionAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("smartTriggerActions/{id:Guid}")]
        public ActionResult<SmartTriggerActionDto> Get([FromRoute] Guid id)
        {
            SmartTriggerActionDto smartTriggerAction = _app.Get(id);
            return Ok(smartTriggerAction);
        }

        [HttpGet]
        [Route("smartTriggers/{smartTriggerId:Guid}/smartTriggerActions")]
        public ActionResult<IEnumerable<SmartTriggerActionDto>> GetList([FromRoute] Guid smartTriggerId)
        {
            IEnumerable<SmartTriggerActionDto> list = _app.GetList(smartTriggerId);
            return Ok(list);
        }

        [HttpPut]
        [Route("smartTriggerActions/{id:Guid}")]
        public ActionResult<SmartTriggerActionDto> Put([FromRoute] Guid id, [FromBody] SmartTriggerActionUpdateDto dto)
        {
            SmartTriggerActionDto smartTriggerAction = _app.Update(id, dto);
            return Ok(smartTriggerAction);
        }

        [HttpPost]
        [Route("smartTriggers/{smartTriggerId:Guid}/smartTriggerActions")]
        public ActionResult<SmartTriggerActionDto> Post([FromRoute] Guid smartTriggerId, [FromBody] SmartTriggerActionCreateDto dto)
        {
            SmartTriggerActionDto smartTriggerAction = _app.Add(smartTriggerId, dto);
            return CreatedAtAction(nameof(Get), new { id = smartTriggerAction.Id }, smartTriggerAction);
        }

        [HttpDelete]
        [Route("smartTriggerActions/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
